package com.cryptoneedle.garden.repository.source.metadata;


import com.bubbles.engine.data.core.repository.BaseRepository;
import com.cryptoneedle.garden.entity.source.metadata.SourceDatabase;
import com.cryptoneedle.garden.key.DatabaseKey;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>description: 源数据源-数据库 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Repository
public interface SourceDatabaseRepository extends BaseRepository<SourceDatabase, DatabaseKey> {

    @Query("  FROM SourceDatabase " +
            "ORDER BY catalogName, enabled DESC, databaseName")
    List<SourceDatabase> databases();

    @Query("  FROM SourceDatabase " +
            "WHERE catalogName = :catalogName " +
            "ORDER BY catalogName, enabled DESC, databaseName")
    List<SourceDatabase> databases(String catalogName);

    @Query("  FROM SourceDatabase " +
            "WHERE enabled = TRUE " +
            "ORDER BY catalogName, enabled DESC, databaseName")
    List<SourceDatabase> databasesEnabled();

    @Query("  FROM SourceDatabase " +
            "WHERE enabled = TRUE " +
            "  AND catalogName = :catalogName " +
            "ORDER BY catalogName, enabled DESC, databaseName")
    List<SourceDatabase> databasesEnabled(String catalogName);
}